from bingo.apps.blog import forms
from bingo.apps.blog.models import Entry

@login_required
def edit_entry(request, slug=None):
    if request.POST:
        post_data = request.POST.copy()
        form = forms.FormEntry(post_data)
        if form.is_valid():
            form.save(slug)
            return HttpResponseRedirect('/')
    elif slug:
        entry = Entry.objects.get(slug=slug)
        form = forms.FormEntry(entry.__dict__)
    else:
        form = forms.FormEntry()
    return render_to_response(
        'central/entry.html', 
        { 'form': form.as_p() },
        context_instance=RequestContext(request),
    )

@login_required
def delete_entry(request, slug):
    form = forms.FormEntry()
    form.delete(slug=slug)
    return HttpResponseRedirect('/')
